module.exports = function ($scope, $state, $resource, $modal, center_list2) {

	$scope.maxSize = '5';			//最多显示多少个按钮
    $scope.currentPage = '1';		//当前页码
    $scope.itemsPerPage = '20'		//每页显示几条

	//页面控制对象
	$scope.item_set = {
		//服务编码下拉菜单
		'center_code': center_list2,
		//接口类型下拉菜单
		'type': [
			{ 'label': '新增', 'value': '1' },
			{ 'label': '已有', 'value': '0' }
		]
	};

	//搜索
	$scope.search = function (){
		var para = {
            'pageNo': $scope.currentPage,
            'pageSize': $scope.itemsPerPage,
			'center_code': $scope.search.center_code.value,
			'type': $scope.search.type.value,
			'url': $scope.search.url,
		};
		$resource('/api/ac/sc/systemFunction/getUserVisitList', {}, {}).save(para, function(res){
			if(res.errcode === 0){
				$scope.apiList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
				$scope.item_set.btn = false;
				if(para.type == '1'){
					$scope.item_set.btn = true;
					angular.forEach($scope.apiList, function(api){
						api.state = true;
					});
				}
			}else{
				alert(res.errmsg);
			}
		});
	};

	init();
	//初始化页面信息
	function init(){
		$scope.search.center_code = $scope.item_set.center_code[0];
		$scope.search.type = $scope.item_set.type[0];
		$scope.search();
	};

	//开启用户侧接口
	$scope.open = function (item){
		var modalInstance = $modal.open({
			template: require('../views/openuserapi.html'),
			controller: 'openUserAPI',
			size: 'lg',
			resolve: {
				item : function () {
					return item;
				},
				flag : function () {
					return true;
				}
			}
		});
		modalInstance.result.then(function(result) {
			$scope.search();
		});
	};

	//修改用户侧接口
	$scope.update = function (item){
		var modalInstance = $modal.open({
			template: require('../views/openuserapi.html'),
			controller: 'openUserAPI',
			size: 'lg',
			resolve: {
				item : function () {
					return item;
				},
				flag : function () {
					return false;
				}
			}
		});
		modalInstance.result.then(function(result) {
			item.name = result.name;
			item.remarks = result.remarks;
			item.state = result.state=='0'?false:true;
			item.type = result.type=='1'?true:false;
		});
	};

	//删除
	$scope.delete = function (index) {
		$resource('/api/as/sc/uservisit/delUserVisit', {}, {}).save({'id': $scope.apiList[index].id}, function(res){
			if(res.errcode === 0){
				$scope.apiList.splice(index,1);
			}else{
				alert(res.errmsg);
			}
		});
    };



};